package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.service.HelloWorldService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import javax.annotation.Resource;

/**
 * TODO 类功能介绍及重点或容易混淆点的说明。
 *
 * @version 1.0 2023/5/22 8:14 龙小南 新建类[说明]
 * @author: 龙小南
 * @Date: 2023/5/22 8:14
 * @Version 1.0[当前版本号]
 */
@Slf4j
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Resource
    private HelloWorldService helloWorldService;

    @Resource
    private Scheduler scheduler;

    @GetMapping("/hello1")
    public Mono<String> helloWord(String id){
        log.error(">>>>>>>>>>>>>");
        return Mono.just("Hello WebFlux!")
//                .publishOn(Schedulers.boundedElastic())
                .publishOn(scheduler)
                .map(s -> helloWorldService.helloWord(id));
    }

    @GetMapping("/hello2")
    public String helloWord2(String id){
        log.error(">>>>>>>>>>>>>");
        BAPTEST6EFFOWU6U7LSDdK7A147eIRP
        return helloWorldService.helloWord(id);
    }

    public static void main(String[] args) {
        Flux.create((t) -> {
            t.next("create");
            t.next("create1");
            t.complete();
        }).subscribe(System.out::println);
    }
}
